﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;
namespace T.FAS.Runtime.Metadata.Entity.Page
{
    /// <summary>
    /// 界面UI控件
    /// </summary>
    [DataContract]
    [Serializable]
    [JsonConverter(typeof(PageUIControlJsonConverter))]
    public class PageUIControl : ICloneable
    {
        /// <summary>
        /// 主键
        /// </summary>
        [DataMember(Name = "ID")]
        public string ID { get; set; }
        /// <summary>
        /// PageID
        /// </summary>
        public string PageID { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public int ControlOrder { get; set; }
        /// <summary>
        /// 控件名称，例如"name": "单行文本",
        /// </summary>
        [DataMember]
        public string Name { get; set; }
        /// <summary>
        /// 组件ID
        /// </summary>
        [DataMember]
        public string CompID { get; set; }       
        /// <summary>
        /// 控件的类型，例如 "type": "tinput",
        /// </summary>        
        /// <remarks>关联对应TComponentId</remarks>
        [DataMember]
        public string CtrlType { get; set; }
        /// <summary>
        /// CSS样式
        /// </summary>
        [DataMember]
        public PageCSS CSS { get; set; }
        /// <summary>
        /// 实例标识
        /// </summary>
        [DataMember]
        public string InstanceCode { get; set; }
        /// <summary>
        /// 默认值
        /// </summary>
        [DataMember]
        public string DefaultValue { get; set; }
        /// <summary>
        /// 父级控件
        /// </summary>
        public string ParentID { get; set; }
        /// <summary>
        /// Options
        /// </summary>
        [DataMember]
        public string Options { get; set; }
        /// <summary>
        /// Options
        /// </summary>
        [DataMember]
        public string Rules { get; set; }
        /// <summary>
        /// DOM类型枚举
        /// </summary>
        public DomType DomType { get; set; }
        ///// <summary>
        ///// 依赖元数据
        ///// </summary>
        //[DataMember]
        //public List<PageUIControlDependency> MetaDependencys { get; set; } = new List<PageUIControlDependency>();
        /// <summary>
        /// 控件的各种属性配置 已忽略
        /// </summary>
        [DataMember]
        public List<object> Properties { get; set; } = new List<object>();
        /// <summary>
        /// 控件上挂载的事件列表
        /// </summary>
        [DataMember]
        public List<PageEvent> Events { get; set; } = new List<PageEvent>();
        /// <summary>
        /// 内嵌子控件列表
        /// </summary>
        [DataMember]
        public List<PageUIControl> Children { get; set; } = new List<PageUIControl>();

        /// <summary>
        /// Json序列化Children对象的名称
        /// </summary>
        [DataMember]
        public string ChildrenSerializeName { get; set; }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
